<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增API开发')"/>
</head>
<body>
<style>
    .flow-node{
        width:300px;
        text-align: left;
    }
</style>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">

        <div class="layui-form-item">
            <label class="layui-form-label">API图标：</label>
            <div class="layui-input-block">
                <input type="text" id="icon" name="icon" placeholder="请输入API图标"
                    class="layui-input" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编码：</label>
            <div class="layui-input-block">
                <input type="text" name="code" placeholder="请输入编码"
                       class="layui-input"  lay-verify="required"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">API名称：</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入API名称"
                       class="layui-input"  lay-verify="required"/>
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label">Path：</label>
                <div class="layui-input-block">
                    <input type="text" name="path" placeholder="请输入Path"
                           class="layui-input"  lay-verify="required"/>
                </div>
            </div>
        <div class="layui-form-item">
            <label class="layui-form-label">API描述：</label>
            <div class="layui-input-block">
                <textarea type="text" name="apiDesc" placeholder="请输入API描述"
                          class="layui-textarea"></textarea>
            </div>
        </div>

            <div class="layui-form-item">
                <label class="layui-form-label">编排：</label>
                <div class="layui-input-block">
                    <ul class="layui-timeline">
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis"></i>
                            <div class="layui-timeline-content layui-text">
                                <div class="layui-btn layui-btn-normal flow-node">HTTP 请求</div>
                                <p>
                                    Post /api/demo/test。
                                    <br>
                                    <br>
                                </p>
                            </div>
                        </li>
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis"></i>
                            <div class="layui-timeline-content layui-text">
                                <div class="layui-btn layui-btn-normal flow-node">MySQL连接器</div>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <p>从中间表抓取数据
                                    <br>
                                    <br>
                                </p>
                            </div>
                        </li>
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis"></i>
                            <div class="layui-timeline-content layui-text">
                                <div class="layui-btn layui-btn-normal flow-node">Bean处理器</div>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <p>
                                    映射成OMS的订单格式
                                    <br>
                                    <br>
                                </p>
                            </div>
                        </li>
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis"></i>
                            <div class="layui-timeline-content layui-text">
                                <div class="layui-btn layui-btn-normal flow-node">Http Client</div>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon"></i></button>
                                <p>
                                    将报文发给OMS系统
                                    <br>
                                    <br>
                                </p>
                            </div>
                        </li>
                        <li class="layui-timeline-item">
                            <i class="layui-icon layui-timeline-axis"></i>
                            <div class="layui-timeline-content layui-text">
                                <div class="layui-btn layui-btn-normal flow-node">HTTP 响应</div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="api-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
</body>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    layui.use(['form', 'jquery', 'laydate', 'iconPicker', 'dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;
        let iconPicker = layui.iconPicker;
        let prefix = "/ipaas/api/"


        iconPicker.render({
            elem: '#icon',
            type: 'fontClass',
            search: true,
            page: true,
            limit: 16
        });

        form.on('submit(api-save)', function (data) {
            for (var key in data.field) {
                var type = $(data.form).find("input[name='" + key + "']").attr("type");
                if (type == "checkbox") {
                    var value = "";
                    $(data.form).find("input[name='" + key + "']:checked").each(function () {
                        value += $(this).val() + ",";
                    })
                    if (value != "") {
                        value = value.substr(0, value.length - 1);
                        data.field[key] = value;
                    }

                }
            }
            $.ajax({
                url: prefix + 'save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.layui.table.reload("api-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    });
</script>
</html>